<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/wx/page/session.jsp"%>
<c:set var="userId" value="${param.userId}" />
<c:set var="deptId" value="${param.deptId}" />
<c:set var="deptCode" value="${param.deptCode}" />
<c:set var="deptParentId" value="${param.deptParentId}" />
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <title>货主管理</title>
    <link rel="stylesheet" href="${ctx}/wx/css/default.css"/>
    <link rel="stylesheet" href="${ctx}/wx/css/xtable.css"/>
    <link rel="stylesheet" href="${ctx}/wx/css/picker.css"/>
    <script type="text/javascript" src="${ctx}/wx/js/picker.min.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/picker.data.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/alert.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/UserService.js"></script>
</head>
<body>
<p class="contact-submit">
    <input type="button" value="添加货主" onclick="insertSender()">
    <input type="hidden" id="staffType" name="staffType" />
</p>

<p class="contact-input">
    <input type="search" id="areaName" name="areaName" placeholder="省 市 区" onfocus="picker3(this)" required readonly />
    <input type="hidden" id="provinceId" name="provinceId" />
    <input type="hidden" id="cityId" name="cityId" />
    <input type="hidden" id="districtId" name="districtId" />
</p>
<SCRIPT LANGUAGE="JavaScript" type="">
    var senderThead = new Array(
            new XThead("货主"),
            new XThead("电话"),
//            new XThead("最近任务")
            new XThead("操作")
    );

    var senderXTable = new XTable("sender", senderThead);

    senderXTable.XTbodyArray = function (model) {
        var staffType = dwr.util.getValue("staffType");
        var href = "<input type=button value='创建任务' onclick=insertTask('" + model.userId + "')>";
        var array = new Array(
                new XTbody("sender", "<a href='${ctx}/wx/page/sender_manage.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&senderId=" + model.senderId + "'>" + model.user.userName + "</a>", null, null, null, "center"),
                new XTbody("sender", "<a href='tel:" + model.user.userMobile + "'>" + model.user.userMobile + "</a>", null, null, null, "center"),
//                new XTbody("sender", model.senderLastDest + "<br/>" + model.senderLastGood, null, null, null, "center")
                new XTbody("sender", href, null, null, null, "center")
        );

        return array;
    }
    senderXTable.getXList = function (page){
        var sender = new Sender();
        sender.provinceId = dwr.util.getValue("provinceId");
        sender.cityId = dwr.util.getValue("cityId");
        sender.districtId = dwr.util.getValue("districtId");
        //if("${deptParentId}" == "1"){
        //    sender.deptParentId = "${deptId}";
        //} else {
        sender.deptParentId = "${deptParentId}";
        //}
        sender.pageIndex = page;
        sender.pageSize = senderXTable.pageSize;
        UserService.selectSenderList(sender, function(list){senderXTable.addTable(list);});
    }
    function getSenderPage(){
        var sender = new Sender();
        sender.provinceId = dwr.util.getValue("provinceId");
        sender.cityId = dwr.util.getValue("cityId");
        sender.districtId = dwr.util.getValue("districtId");
        //if("${deptParentId}" == "1"){
        //    sender.deptParentId = "${deptId}";
        //} else {
        sender.deptParentId = "${deptParentId}";
        //}
        UserService.selectSenderNum(sender, function(num){senderXTable.setTotalPage(num);});
    }
</SCRIPT>
</body>
</html>
<script type="text/javascript">
    var staff = new Staff();
    staff.userId = "${userId}";
    UserService.selectStaffList(staff, function (list) {
        staff = list[0];
        dwr.util.setValue("staffType", staff.staffType);
        getSenderPage();
    });
    function picker3(input) {
        new Picker({
            //"title": '请选择',//标题(可选)
            "defaultValue": input.value,//默认值-多个以空格分开（可选）
            "data": cityData,//数据(必传)
            "keys": {
                "id": "Code",
                "value": "Name",
                "childData": "level"//最多3级联动
            },//数组内的键名称(必传，id、text、data)
            "callBack": function (value, areaId) {
                //回调函数（val为选择的值）
                input.value = value;
                var array = areaId.split(" ");
                dwr.util.setValue("provinceId", array[0]);
                dwr.util.setValue("cityId", array[1]);
                dwr.util.setValue("districtId", array[2]);
                getSenderPage();
            }
        });
    }
    function insertTask(senderUserId) {
        var staffType = dwr.util.getValue("staffType");
        location = "${ctx}/wx/page/task_manage.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&staffType=" + staffType + "&taskType=2&senderUserId=" + senderUserId;
    }
    function insertSender() {
        location = "${ctx}/wx/page/sender_manage.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}";
    }
</script>